<%@include file="/WEB-INF/pages/commons/commons.jsp" %>

<stripes:layout-render name="${_themePath}/basic-layout-without-navbar.jsp" _title="Add Resource">

    <stripes:layout-component name="_head">
        <script type="text/javascript">
            // === resourceHeaderMenu
                YAHOO.util.Event.onContentReady("resourceHeaderMenu", function() {
                    var manageHeaderMenu = new YAHOO.widget.Button("resourceHeaderMenuButton",
                                            { type: "menu", menu: "resourceHeaderMenuButtonSelect" });
                    //	"click" event listener for the second Button's Menu instance
                    var onMenuClick = function (p_sType, p_aArgs) {
                        var oEvent = p_aArgs[0];	//	DOM event
                        var oMenuItem = p_aArgs[1];	//	MenuItem instance that was the
                                                    //	target of the event
                        if (oMenuItem) {
                            if ('0' == oMenuItem.value) {   // Edit Page Of This Resource
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.EditPageActionBean" event="view">
                                        <stripes:param name="currentPage" value="${actionBean.page.id}"/>
                                </stripes:url>
                                document.location.href = '${url}';
                            }
                            else if ('1' == oMenuItem.value) { // Show Page Of This Resource As Wiki Page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.PageActionBean" event="view">
                                    <stripes:param name="page" value="${actionBean.page.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else {
                                alert('unrecognized menu option');
                            }
                        }
                    };
                    //	Add a "click" event listener for the Button's Menu
                    manageHeaderMenu.getMenu().subscribe("click", onMenuClick);
                });
        </script>
    </stripes:layout-component>

    <stripes:layout-component name="_topNav">
        <H1>Add Resource</H1>
        <UL class="gc-topnav-tabs">
            <LI>
                <span id="resourceHeaderMenu">
                <input type="button" id="resourceHeaderMenuButton" value="Options"/>
                <select id="resourceHeaderMenuButtonSelect">
                    <option value="0">Edit Page Of This Resource</option>
                    <option value="x">&nbsp;</option>
                    <option value="1">Show Page Of This Resource As Wiki Page</option>
                </select>
                </span>
            </LI>
        </UL>
    </stripes:layout-component>

    <stripes:layout-component name="_content">
        <stripes:messages/>
        <h2>Description[<a id="_showDescription" href="#">Show</a>/<a id="_hideDescription" href="#">Hide</a>]</h2>
        <div id="_description">
        <p>
            This is where you'd add the resource of page [${actionBean.page.name}]. The file size should be less
            than 1Meg. The parameters are as follows :-
            <ul>
                <li>Name - the name of the resource, required</li>
                <li>File - the resource itself, could be pdf, image etc.</li>
            </ul>
        </p>
        <p>
            You can access the resource through the following syntax
            <pre>
                {#resourceName}
            </pre>
        </p>
        <p/>
        <p/>
        <p/>
        </div>

        <h2>Add Resource</h2>
        <jsecurity:hasPermission name="space:editSpace:${actionBean.page.spaceId}">
        <stripes:form beanclass="foo.bar.wiki.web.action.resource.AddResourceActionBean" method="POST"
                      enctype="multipart/form-data">
            <stripes:errors/>
            <stripes:hidden name="resource" value=""/>
            <stripes:hidden name="page" value="${actionBean.page.id}"/>
            <table width="100%">
                <tr>
                    <td>Name</td>
                    <td><stripes:text name="resource.name" /></td>
                </tr>
                <tr>
                    <td>File</td>
                    <td><stripes:file name="file" /></td>
                </tr>
                <tr>
                    <td colspan="2"><stripes:submit name="save">Save</stripes:submit></td>
                </tr>
            </table>
        </stripes:form>
        </jsecurity:hasPermission>
        <jsecurity:lacksPermission name="space:editSpace:${actionBean.page.spaceId}">
            Lacks "space:editSpace:${actionBean.page.spaceId}" permission   
        </jsecurity:lacksPermission>
    </stripes:layout-component>

</stripes:layout-render>



